// 1.导入mockjs
import Mock from 'mockjs'

// const url = {
//  tableDataOne: 'http://192.168.14.75:9090/api/goodsSpecies',
//  tableDataTwo: 'http://20181024Mock.com/mode1/tableDataTwo',
//  tableDataThi: 'http://20181024Mock.com/mode1/tableDataThi'
// }
// 根据自己的需要有时候需要创建一些随机的数据
Mock.Random.extend({
  goodsSpecies: function () {
    const arr = [{ speciesId: 's1', text: '秋冬滋补' }, { speciesId: 's1', text: '水果区' }, { speciesId: 's1', text: '蔬菜区' }, { speciesId: 's1', text: '家禽区' }, { speciesId: 's1', text: '水产区' }, { speciesId: 's1', text: '肉类区' }, { speciesId: 's1', text: '蛋类区' }, { speciesId: 's1', text: '豆制品' }, { speciesId: 's1', text: '调味品' }, { speciesId: 's1', text: '小狐新品' }, { speciesId: 's1', text: '小狐精选' }, { speciesId: 's1', text: '鲜奶乳品' }, { speciesId: 's1', text: '休闲食品' }]
    return this.pick(arr)
  }
})

// 2.使用mock方法来拦截请求
// mock方法的第一个参数字符串是 拦截的请求地址
// mock方法的第二个参数是 拦截的请求形式
// mock方法的第三个参数是一个函数，当拦截请求成功之后，会执行这个函数，并且将函数的返回值
// 作为请求的结果。

/**
 * 获取商品种类列表
 */

Mock.mock('http://192.168.14.75:9090/api/goodsSpecies', 'get',
  function () {
    var data = Mock.mock({
      goodsSpecies: [{ speciesId: 's1', text: '秋冬滋补' }, { speciesId: 's2', text: '水果区' }, { speciesId: 's3', text: '蔬菜区' }, { speciesId: 's4', text: '家禽区' }, { speciesId: 's5', text: '水产区' }, { speciesId: 's6', text: '肉类区' }, { speciesId: 's7', text: '蛋类区' }, { speciesId: 's8', text: '豆制品' }, { speciesId: 's9', text: '调味品' }, { speciesId: 's10', text: '小狐新品' }, { speciesId: 's11', text: '小狐精选' }, { speciesId: 's12', text: '鲜奶乳品' }, { speciesId: 's13', text: '休闲食品' }]
    })
    return data
  })

/**
 * 根据种类id获取商品列表
 */
// Mock.mock(/^http:\/\/192\.168\.14\.75:9090\/api\/goodsList\/s\d+/, 'get',
//   function () {
//     var data = Mock.mock({
//       data: 'success'
//     })
//     return data
//   })

/**
 * 根据种类id获取商品列表(requestH)
 * /\/goodsList*?/
 * /\/goodsList\?id=s\d+/
 */
const goodsList = [
  {
    speciesId: 's1',
    data: [
      {
        goodsCar_num: 1,
        goodsId: 11,
        goods_img: 'https://s1.ax1x.com/2020/10/17/0L5qdf.jpg',
        goods_name: '进口男模 国外的 130斤一份',
        get_time: '10月19日',
        origin_price: '10.0',
        current_price: '9.9',
        be_sold: '0',
        unsold: '1',
        origin_place: '巴西'
      },
      {
        goodsCar_num: 1,
        goodsId: 12,
        goods_img: 'https://s1.ax1x.com/2020/10/17/0Lozbq.png',
        goods_name: '进口蓝莓蛋糕 蓝莓田里刚摘的 3斤一份',
        get_time: '10月19日',
        origin_price: '2499.0',
        current_price: '2195.0',
        be_sold: '282',
        unsold: '555',
        origin_place: '长沙'
      },
      {
        goodsCar_num: 1,
        goodsId: 13,
        goods_img: 'https://s1.ax1x.com/2020/10/17/0LTgZq.png',
        goods_name: '猕猴桃滞销 救救我们 20斤一份',
        get_time: '10月19日',
        origin_price: '22.0',
        current_price: '20.0',
        be_sold: '222',
        unsold: '555',
        origin_place: '巴西'
      }
    ]
  },
  {
    speciesId: 's2',
    data: [
      {
        goodsCar_num: 1,
        goodsId: 21,
        goods_img: 'https://w.wallhaven.cc/full/od/wallhaven-odopgl.jpg',
        goods_name: '草莓派 九折水瓶 2斤一份',
        get_time: '10月19日',
        origin_price: '10.0',
        current_price: '9.9',
        be_sold: '0',
        unsold: '1',
        origin_place: '巴西'
      },
      {
        goodsCar_num: 1,
        goodsId: 22,
        goods_img: 'https://s1.ax1x.com/2020/10/17/0LTgZq.png',
        goods_name: '猕猴桃滞销 救救我们 20斤一份',
        get_time: '10月19日',
        origin_price: '22.0',
        current_price: '20.0',
        be_sold: '222',
        unsold: '555',
        origin_place: '巴西'
      },
      {
        goodsCar_num: 1,
        goodsId: 23,
        goods_img: 'https://s1.ax1x.com/2020/10/17/0Lozbq.png',
        goods_name: '进口蓝莓蛋糕 蓝莓田里刚摘的 3斤一份',
        get_time: '10月19日',
        origin_price: '2499.0',
        current_price: '2195.0',
        be_sold: '282',
        unsold: '555',
        origin_place: '长沙'
      }
    ]
  },
  {
    speciesId: 's3',
    data: [
      {
        goodsCar_num: 1,
        goodsId: 31,
        goods_img: 'https://w.wallhaven.cc/full/nk/wallhaven-nkgr1m.jpg',
        goods_name: 'G-Timeless腕表，27毫米',
        get_time: '10月19日',
        origin_price: '7400',
        current_price: '6900',
        be_sold: '0',
        unsold: '1',
        origin_place: '瑞士'
      },
      {
        goodsCar_num: 1,
        goodsId: 32,
        goods_img: 'https://w.wallhaven.cc/full/nm/wallhaven-nm66rk.jpg',
        goods_name: 'TAGHeuer系列腕表，38毫米',
        get_time: '10月19日',
        origin_price: '13600',
        current_price: '12900',
        be_sold: '282',
        unsold: '555',
        origin_place: '瑞士'
      },
      {
        goodsCar_num: 1,
        goodsId: 33,
        goods_img: 'https://w.wallhaven.cc/full/0j/wallhaven-0jjjoq.jpg',
        goods_name: '卡西欧G-SHOCK发布HondaJet合作表款',
        get_time: '10月19日',
        origin_price: '9999',
        current_price: '8899',
        be_sold: '222',
        unsold: '555',
        origin_place: '巴西'
      },
      {
        goodsCar_num: 1,
        goodsId: 33,
        goods_img: 'https://w.wallhaven.cc/full/4d/wallhaven-4dozgm.jpg',
        goods_name: '卡西欧G-SHOCK发布HondaJet合作表款',
        get_time: '10月19日',
        origin_price: '18990',
        current_price: '16999',
        be_sold: '222',
        unsold: '555',
        origin_place: '巴西'
      }
    ]
  },
  {
    speciesId: 's4',
    data: [
      {
        goodsCar_num: 1,
        goodsId: 41,
        goods_img: 'https://w.wallhaven.cc/full/0w/wallhaven-0w9k7r.jpg',
        goods_name: '独家超级男模 可以租借 以天算',
        get_time: '10月19日',
        origin_price: '699',
        current_price: '399',
        be_sold: '0',
        unsold: '1',
        origin_place: '瑞士'
      },
      {
        goodsCar_num: 1,
        goodsId: 42,
        goods_img: 'https://w.wallhaven.cc/full/n6/wallhaven-n66y26.jpg',
        goods_name: '家用女模 可供观赏 以月算',
        get_time: '10月19日',
        origin_price: '13600',
        current_price: '12900',
        be_sold: '282',
        unsold: '555',
        origin_place: '瑞士'
      },
      {
        goodsCar_num: 1,
        goodsId: 43,
        goods_img: 'https://w.wallhaven.cc/full/3k/wallhaven-3k8839.jpg',
        goods_name: '游玩女模 可陪伴出游 以天算',
        get_time: '10月19日',
        origin_price: '799',
        current_price: '599',
        be_sold: '222',
        unsold: '555',
        origin_place: '巴西'
      },
      {
        goodsCar_num: 1,
        goodsId: 44,
        goods_img: 'https://w.wallhaven.cc/full/4y/wallhaven-4yyy3k.jpg',
        goods_name: '话唠女模 无聊来一位 以天算',
        get_time: '10月19日',
        origin_price: '500',
        current_price: '200',
        be_sold: '222',
        unsold: '555',
        origin_place: '巴西'
      }
    ]
  }
]
Mock.mock(/\/goodsList\?id=s\d+/, 'get',
  options => {
    let resultId = options.url.replace('/goodsList?id=', '')
    let result = []
    if (resultId !== 's1' && resultId !== 's2' && resultId !== 's3' && resultId !== 's4') {
      resultId = 's4'
      goodsList.forEach(item => {
        if (item.speciesId === resultId) {
          result = item
        }
      })
    } else {
      goodsList.forEach(item => {
        if (item.speciesId === resultId) {
          result = item
        }
      })
    }
    //var data = Mock.mock({ data: result })
    return result
  })
